<?php
if($_SESSION['rank'] < 2){
	exit(Lang::getBackGlobal('wrong_permissions'));
}
?>
<?php

/**
 * @author Martin Pernica
 * @copyright 2008
 */
if(empty($_GET['name'])){


echo '<table style="color: black;" class="clean_table" >';
echo '<tr><th></th><th>'.Lang::getBackGlobal('components_name').'</th><th>'.Lang::getBackGlobal('components_version').'</th><th>'.Lang::getBackGlobal('components_author').'</th></tr>';
$components = dirlist('../components');
for($i = 0; !empty($components[$i]); $i++){
	if(is_file('..'.DIR_SEP.'components'.DIR_SEP.$components[$i].DIR_SEP.'admin'.DIR_SEP.'icon.png')){
        $icon = '..'.DIR_SEP.'components'.DIR_SEP.$components[$i].DIR_SEP.'admin'.DIR_SEP.'icon.png';
	}else{
		$icon = '.'.DIR_SEP.'components'.DIR_SEP.'com_components'.DIR_SEP.'none.png';
	}
	
	if(is_file('..'.DIR_SEP.'components'.DIR_SEP.$components[$i].DIR_SEP.'info.xml')){

    $xml = simplexml_load_file('..'.DIR_SEP.'components'.DIR_SEP.$components[$i].DIR_SEP.'info.xml');
    $name = (string)$xml->info[0]->name;
    $version = (string)$xml->info[0]->version;
    $actual_version = file_get_contents((string)$xml->info[0]->version_url);
    $description = 'title="'.(string)$xml->info[0]->description.'"';
    $autor = (string)$xml->info[0]->author;

	}else{
		$name = $components[$i];
		$version = 'unknown';
        $actual_version = 'unknown';
        $autor = 'Unknown';
	}
	
	$component = explode('_', $components[$i]);

	echo '<tr class="component" onclick="location.href=\''.$_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'].'&name='.$component[1].'\'" onmouseover="this.style.background = \'white\'" onmouseout="this.style.background = \'#f5f5f5\'" '.$description.' ><td><img src="'.$icon.'"</td><td><strong>'.$name.'</strong></td><td><em>'.$version.' / '.$actual_version.'</em></td><td>'.$autor.'</td></tr>';
}
echo '</table>';
}
else if(is_file('..'.DIR_SEP.'components'.DIR_SEP.'com_'.$_GET['name'].DIR_SEP.'admin'.DIR_SEP.'admin.php')){
    if($_SESSION['rank'] < intval(getPermission($_GET['name']))){
	exit(WRONG_PERMISSIONS);
	}else{
        require '..'.DIR_SEP.'components'.DIR_SEP.'com_'.$_GET['name'].DIR_SEP.'admin'.DIR_SEP.'admin.php';
	}
}else{
	echo '<h1>'.Lang::getBackGlobal('components_nosetting').'</h1>';
}
?>